package com.hna.face.common.utils;


import java.util.ArrayList;
import java.util.List;

import com.hna.face.model.TreeNode;


/**
 * 构建tree
 * TODO
 * <br>
 * @author kangxu2 2017-1-7
 *
 */
public class BuildTree {

    public static List<TreeNode> build(List<TreeNode> list){
    	List<TreeNode> nodeList = new ArrayList<TreeNode>();  
		for(TreeNode node1 : list){  
    	    boolean mark = false;  
    	    for(TreeNode node2 : list){  
    	        if(node1.getParentId()!=null && node1.getParentId().equals(node2.getId())){  
    	            mark = true;  
    	            if(node2.getChildren() == null)  
    	                node2.setChildren(new ArrayList<TreeNode>());  
    	            node2.getChildren().add(node1);   
    	            break;  
    	        }  
    	    }  
    	    if(!mark){  
    	        nodeList.add(node1);   
    	    }  
    	}  
		
		return nodeList;
    }

}
